package com.tcxhb.job.admin.convert;

import com.tcxhb.job.dao.dataobject.JobInfoDO;
import com.tcxhb.job.dao.dataobject.query.JobInfoQuery;
import com.tcxhb.job.admin.model.request.biz.JobInfoAddReq;
import com.tcxhb.job.admin.model.request.query.JobInfoQueryReq;
import com.tcxhb.job.admin.model.response.JobInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.Date;

@Mapper(componentModel = "spring")
public interface JobInfoConvert {

    @Mappings({
            @Mapping(target = "nextDateTime", expression = "java(toDate(job.getNextTime()))"),
    })
    public JobInfoVO do2VO(JobInfoDO job);

    public JobInfoQuery toQuery(JobInfoQueryReq req);

    public JobInfoDO req2DO(JobInfoAddReq addReq);


    default Date toDate(Long timestamp) {
        if (timestamp == 0) {
            return null;
        }
        return new Date(timestamp);
    }

}
